<template>
  <div id="payment">
    <div class="top">金额  <span>请填写支付金额</span></div>
    <div class="payInput">
        <input type="text" v-model="price" class="payInputItem">
        <span>元</span>
    </div> 
    <x-button type="primary" class="zhifu" @click.native ="payBtn" @change="changes">立即支付</x-button>
  </div>
</template>
<script>
    import { XButton ,Toast} from 'vux'
    import store from '@/vuex/store'

    export default {
        data(){
            return{
                price:'',
                out_trade_no:'',
                sign:'',
                oldprice:'',
                orderId:'',
                orderState:false
            }
        },
         mounted:function(){
            var cHeight = document.body.clientHeight;
            document.getElementById('payment').style.height = cHeight+'px'
            console.log(cHeight)
            console.log(1)
            // document.getElementById('payBox').style.height = cHeight+'px';
        },
        methods:{
            changes(){
                console.log('change')
                
            },
            payBtn(){
                var _this = this;
                var orderId = _this.$store.state.allDate.id;
                var price = _this.price;
                if(_this.price === "" || _this.price < 0){
                    _this.$vux.toast.show({
                        text:'请正确填写金额'
                    })
                    return false
                } 
                $.ajax({
                    url:'http://bg.test.baimixu.cn/index.php?m=Home&c=SendApi&a=updatePaymentAmount',
                    data:{price:price,id:orderId},
                    type:'get',
                    dataType:'jsonp',
                    async: true,
                    success(data){
                        if(data.success){
                            _this.oldprice = data.d.money
                            _this.orderId = data.d.id
                            _this.out_trade_no = data.d.orderNum
                            _this.sign = data.d.sign
                            var allDates = {
                                debug:true,
                                title:'在线寄包裹费用',
                                amount:_this.oldprice,
                                out_trade_no:_this.out_trade_no,
                                sign:_this.sign,
                                openid:_this.$store.state.openId
                            }  
                            BC.click(allDates,function(res){
                                console.log(res)
                            })  
                        }else{
                            alert('失败了')
                        }
                        
                    }
                })
                                     
            }
        },
        components:{
            XButton,
            Toast
        },
        store
    }
</script>
